import getCurrentLocation from './getCurrentLocation'
import getCities from './getCities'

export default () => {
  return new Promise((resolve, reject) => {
    getCurrentLocation()
      .then(({ districtAdcode }) => {
        resolve(Math.floor(districtAdcode / 100) * 100)
      })
      .catch(async () => {
        getCities()
          .then(({ adcode }) => {
            resolve(adcode)
          })
          .catch(reject)
      })
  })
}
